package com.example.springboot01.controller;

import com.example.springboot01.entity.User;
import com.example.springboot01.req.PageQueryReq;
import com.example.springboot01.resp.Response;
import com.example.springboot01.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/user")
public class UserController {


    @Resource
    private UserService userService;

    @PostMapping
    public Response save(@RequestBody User user){
        userService.save(user);
        return Response.ok(null);
    }

    @PutMapping
    public Response update(@RequestBody User user){
        userService.updateById(user);
        return Response.ok(null);
    }


    @DeleteMapping("/{id}")
    public Response delete(@PathVariable Integer id){
        userService.removeById(id);
        return Response.ok(null).setMsg("删除成功");
    }

    @GetMapping
    public Response list(){
        return Response.ok(userService.list());
    }


    @GetMapping("/page")
    public Response page(PageQueryReq req){
        return Response.ok(null);
    }
}
